import json

from api.ihrm_login_Api import ImHr


class CommonTool:
    @classmethod
    def assert_succeed(cls, self, res, status_code, success, code, message):
        self.assertEqual(status_code, res.status_code)
        self.assertEqual(success, res.json().get("success"))
        self.assertEqual(code, res.json().get("code"))
        self.assertIn(message, res.json().get("message"))

    @classmethod
    def lest_data(cls, file_path):
        with open(file_path, "r", encoding="utf-8") as j:  # 打开test1.json文件
            lis2 = json.load(j)  # 把文件数据传给lis2
        unm = []
        for i in lis2:  # 用循环读取lis2数据
            unm.append(tuple(i.values()))  # 用循环吧一个一个元祖放到列表里
        return unm  # 输出一个元祖列表

    @classmethod
    def get_header(cls):
        json_data = {"mobile": "13800000002", "password": "123456"}
        resp = ImHr.imhr_login(json_data)
        tok = "Bearer " + resp.json().get("data")
        header = {"Authorization": f"{tok}"}
        return header
